<?php
namespace App\Http\Controllers\AppApi\Member;

use App\Services\Admin\CompanyService;
use App\Utilities\Upload;
use Illuminate\Http\Request;

class CompanyController extends BaseController
{
    /**
     * 工厂接口控制器
     * 制作者：九哥
     */

    protected $service;

    public function __construct()
    {
        parent::__construct();
        $this->service = new CompanyService();
    }

    /**
     * ---------------------------------------
     * 公司信息
     * ---------------------------------------
     */

    /**
     * 公司信息，获取
     * /api/member/company/show
     */
    public function getComShow(Request $request)
    {
        //  exit('/api/member/company/show');
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) { return $this->toJson(-2); }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $model = $this->service->getOneByUid($uid);
      //  print_r($model);exit;
        if (!$model) { return $this->toJson(-3); }
        return $this->toJson(0,$model);
    }

    /**
     * 公司信息，上传
     */
    public function setUpload(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return redirect('/h5/error.html?errMsg=接口权限错误');
        }
        $token = $request->token;
        $cate = $request->cate;
        if (!$token) {
            return redirect('/h5/error.html?errMsg=参数错误');
        }
        $uid = $this->accessGet($token);
        if (!$uid) {
            return redirect('/h5/error.html?errMsg=用户未登录或未注册');
        }
        if (!isset($request->sfzzmFile) && !isset($request->sfzfmFile)
            && !isset($request->sfzscFile)) {
            return redirect('/h5/error.html?errMsg=文件没有上传');
        }
        
//        $facType = $request->facType;
        $viewJump = $request->viewJump;
        $realname = $request->realname ? $request->realname : '';
        $sex = $request->sex;
        $mobile = $request->mobile ? $request->mobile : '';
        $idcard = $request->idcard ? $request->idcard : '';
        $sfzzm = $request->sfzzm ? $request->sfzzm : '';
        $sfzfm = $request->sfzfm ? $request->sfzfm : '';
        $sfzsc = $request->sfzsc ? $request->sfzsc : '';
        $images = array();
        $model = $this->service->getOneByUid($uid);
        if (isset($request->sfzzmFile)) {
            $resFile = Upload::uploadImgByApi($request,'sfzzmFile');
            if ($resFile['code']!=0) {
                return redirect('/h5/error.html?errMsg='.$resFile['msg']);
            }
            $images = array(
                'sfzzm' => $resFile['filePath'],
                'sfzfm' => $sfzfm,
                'sfzsc' => $sfzsc,
            );
            if ($model && $model->legal_idcard_imgs) {
                $imageOlds = explode('|',$model->legal_idcard_imgs);
                if ($resFile['code']==0 && $imageOlds[0] &&
                    file_exists(ltrim($imageOlds[0],'/'))) {
                    unlink(ltrim($imageOlds[0],'/'));
                }
            }
        }
        else if (isset($request->sfzfmFile)) {
            
            $resFile = Upload::uploadImgByApi($request,'sfzfmFile');
            if ($resFile['code']!=0) {
                return redirect('/h5/error.html?errMsg='.$resFile['msg']);
            }
            $images = array(
                'sfzzm' => $sfzzm,
                'sfzfm' => $resFile['filePath'],
                'sfzsc' => $sfzsc,
            );
            if ($model && $model->legal_idcard_imgs) {
                $imageOlds = explode('|',$model->legal_idcard_imgs);
                if ($resFile['code']==0 && $imageOlds[1] &&
                    file_exists(ltrim($imageOlds[1],'/'))) {
                    unlink(ltrim($imageOlds[1],'/'));
                }
            }
        }
        else if (isset($request->sfzscFile)) {
           
            $resFile = Upload::uploadImgByApi($request,'sfzscFile');
            if ($resFile['code']!=0) {
                return redirect('/h5/error.html?errMsg='.$resFile['msg']);
            }
            $images = array(
                'sfzzm' => $sfzzm,
                'sfzfm' => $sfzfm,
                'sfzsc' => $resFile['filePath'],
            );
            if ($model && $model->legal_idcard_imgs) {
                $imageOlds = explode('|',$model->legal_idcard_imgs);
                if ($resFile['code']==0 && $imageOlds[2] &&
                    file_exists(ltrim($imageOlds[2],'/'))) {
                    unlink(ltrim($imageOlds[2],'/'));
                }
            }
        }
        
        $dataArr = array(
            'uid' => $uid,
            'cate' => $cate,
//            'facType' => $facType,
            'legal_name' => $realname,
            'legal_sex' => $sex,
            'legal_mobile' => $mobile,
            'legal_idcard' => $idcard,
            'legal_idcard_imgs' => implode('|',$images),
            //下面给个初始值
            'com_name' => $model?$model->com_name:'',
            'com_tel' => $model?$model->com_tel:'',
            'com_fax' => $model?$model->com_fax:'',
            'com_address' => $model?$model->com_address:'',
            'age_range' => $model?$model->age_range:'',
            'detail' => $model?$model->detail:'',
            'lat' => $model?$model->lat:'',
            'lng' => $model?$model->lng:'',
        );
        $this->service->add($uid,$dataArr);
        return redirect($viewJump);
    }

    /**
     * 企业信息，业务类型
     */
    public function getOutTypeList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $cate = $request->cate;
        if (!$token) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $outTypes = $this->service->getOutTypes($cate);
        return $this->toJson(0,$outTypes);
    }

    /**
     * 企业信息，设置
     */
    public function setModify(Request $request)
    {
         
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $cate = $request->cate;
        if (!$token || !in_array($cate,[1,2,3])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $comInfo = $request->comInfo;
        //城市名称转ID
        $facType = $comInfo['facType'];
        $realname = $comInfo['realname'];
        $sex = $comInfo['sex'];
        $mobile = $comInfo['mobile'];
        $idcard = $comInfo['idcard'];
        $sfzzm = $comInfo['sfzzm'];
        $sfzfm = $comInfo['sfzfm'];
        $sfzsc = $comInfo['sfzsc'];
        $images = array(
            'sfzzm' => $sfzzm,
            'sfzfm' => $sfzfm,
            'sfzsc' => $sfzsc,
        );
        $comName = $comInfo['comName'];
        $comTel = $comInfo['comTel'];
        $comFax = $comInfo['comFax'];
        $comAddress = $comInfo['comAddress'];
        $comCity = $comInfo['comCity'];
        $cusLike = $comInfo['cusLike'];
        $quality = $comInfo['quality'];
        $pact = $comInfo['pact'];
        $param = $comInfo['param'];
        $param2 = $comInfo['param2'];
        $outTypeStr = $comInfo['outTypeStr'];
        $ageRange = $comInfo['ageRange'];
        $detail = $comInfo['detail'];
       /// var_dump($comCity);exit;
        $cityId = $this->service->getCityIdByName($comCity);
        if (!$cityId) { return $this->toJson(-27); }
//        return $this->toJson(-1,$cityId);
        
        
        
        $dataArr = array(
            'facType' => $facType,
            'cate' => $cate,
            'legal_name' => $realname,
            'legal_sex' => $sex,
            'legal_mobile' => $mobile,
            'legal_idcard' => $idcard,
            'legal_idcard_imgs' => implode('|',$images),
            'com_name' => $comName,
            'com_tel' => $comTel,
            'com_fax' => $comFax,
            'com_address' => $comAddress,
//            'com_city' => $comCity,
            'com_city' => $cityId,
            'cus_like' => $cusLike,
            'quality' => $quality,
            'pact' => $pact,
            'param' => $param ? json_encode($param) : '',
            'param2' => $param2 ? json_encode($param2) : '',
            'out_type' => $outTypeStr,
            'age_range' => $ageRange,
            'detail' => $detail,
            'lat' => '',
            'lng' => '',
        );
        $this->service->modify($dataArr,$uid);
        return $this->toJson(0);
    }

    /**
     * ---------------------------------------
     * 公司信息
     * ---------------------------------------
     */





    /**
     * ---------------------------------------
     * 公司认证
     * ---------------------------------------
     */

    /**
     * 公司认证，获取
     */
    public function getFileList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token || !in_array($cate,[1,2,3])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $model = $this->service->getOptionLicence($uid);
        if (!$model) { return $this->toJson(-3); }
        return $this->toJson(0,$model);
    }

    /**
     * 公司信息，上传
     */
    public function setFileUpload(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return redirect('/h5/error.html?errMsg=接口权限错误');
        }
        $token = $request->token;
        $cate = $request->cate;
        $facType = $request->facType;
        $viewJump = $request->viewJump;
        if (!$token || !in_array($cate,[1,2,3])) {
            return redirect('/h5/error.html?errMsg=参数错误');
        }
        $uid = $this->accessGet($token);
        if (!$uid) {
            return redirect('/h5/error.html?errMsg=用户未登录或未注册');
        }
        //图片链接
//        $xxz = $request->xxz!='undefined' ? $request->xxz : '';
//        $sfz = $request->sfz!='undefined' ? $request->sfz : '';
//        $byz = $request->byz!='undefined' ? $request->byz : '';
//        $jz = $request->jz!='undefined' ? $request->jz : '';
//        $jhz = $request->jhz!='undefined' ? $request->jhz : '';
//        $jsz = $request->jsz!='undefined' ? $request->jsz : '';
//        $zzjgdmz = $request->zzjgdmz!='undefined' ? $request->zzjgdmz : '';
//        $yyzz = $request->yyzz!='undefined' ? $request->yyzz : '';
//        $swdjz = $request->swdjz!='undefined' ? $request->swdjz : '';
//        $zlht = $request->zlht!='undefined' ? $request->zlht : '';
//        $xkz = $request->xkz!='undefined' ? $request->xkz : '';
//        $ryzs = $request->ryzs!='undefined' ? $request->ryzs : '';
//        $fcz = $request->fcz!='undefined' ? $request->fcz : '';
        if (!isset($request->fileXxz) && !isset($request->fileSfz) &&
            !isset($request->fileByz) && !isset($request->fileJz) &&
            !isset($request->fileJhz) && !isset($request->fileJsz) &&
            !isset($request->fileZzjgdmz) && !isset($request->fileYyzz)
            && !isset($request->fileSwdjz) && !isset($request->fileZlht)
            && !isset($request->fileXkz) && !isset($request->fileRyzs)
            && !isset($request->fileFcz)) {
            return redirect('/h5/error.html?errMsg=文件没有上传');
        }
//        $resXxz = ''; $resSfz = ''; $resByz = ''; $resJz = ''; $resJhz = '';
//        $resJsz = ''; $resZzjgdmz = ''; $resYyzz = ''; $resSwdjz = '';
//        $resZlht = ''; $resXkz = ''; $resRyzs = ''; $resFcz = '';
        if (isset($request->fileXxz)) {
            $resFile = Upload::uploadImgByApi($request,'fileXxz');
            $fileName = 'photos';
        }
        else if (isset($request->fileSfz)) {
            $resFile= Upload::uploadImgByApi($request,'fileSfz');
            $fileName = 'idcards';
        }
        else if (isset($request->fileByz)) {
            $resFile= Upload::uploadImgByApi($request,'fileByz');
            $fileName = 'graduates';
        }
        else if (isset($request->fileJz)) {
            $resFile= Upload::uploadImgByApi($request,'fileJz');
            $fileName = 'honors';
        }
        else if (isset($request->fileJhz)) {
            $resFile= Upload::uploadImgByApi($request,'fileJhz');
            $fileName = 'marrys';
        }
        else if (isset($request->fileJsz)) {
            $resFile= Upload::uploadImgByApi($request,'fileJsz');
            $fileName = 'drives';
        }
        else if (isset($request->fileZzjgdmz)) {
            $resFile= Upload::uploadImgByApi($request,'fileZzjgdmz');
            $fileName = 'zzjgdmzs';
        }
        else if (isset($request->fileYyzz)) {
            $resFile= Upload::uploadImgByApi($request,'fileYyzz');
            $fileName = 'yyzzs';
        }
        else if (isset($request->fileSwdjz)) {
            $resFile= Upload::uploadImgByApi($request,'fileSwdjz');
            $fileName = 'swdjzs';
        }
        else if (isset($request->fileZlht)) {
            $resFile= Upload::uploadImgByApi($request,'fileZlht');
            $fileName = 'rents';
        }
        else if (isset($request->fileXkz)) {
            $resFile= Upload::uploadImgByApi($request,'fileXkz');
            $fileName = 'licencess';
        }
        else if (isset($request->fileRyzs)) {
            $resFile= Upload::uploadImgByApi($request,'fileRyzs');
            $fileName = 'honorss';
        }
        else if (isset($request->fileFcz)) {
            $resFile= Upload::uploadImgByApi($request,'fileFcz');
            $fileName = 'houses';
        }
        else {
            return redirect('/h5/error.html?errMsg=未知错误');
        }
        if ($resFile['code']!=0) {
            return redirect('/h5/error.html?errMsg='.$resFile['msg']);
        }
        $this->service->setOptionLicence($uid,$fileName,$resFile['filePath']);
        return redirect($viewJump);
    }

    /**
     * 公司认证，链接设置
     */
    public function setFileLink(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token || !in_array($cate,[1,2,3])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $photos = $request->photos;
        $idcards = $request->idcards;
        $graduates = $request->graduates;
        $honors = $request->honors;
        $marrys = $request->marrys;
        $drives = $request->drives;
        $zzjgdmzs = $request->zzjgdmzs;
        $yyzzs = $request->yyzzs;
        $swdjzs = $request->swdjzs;
        $rents = $request->rents;
        $licencess = $request->licencess;
        $honorss = $request->honorss;
        $houses = $request->houses;
        if (!$photos && !$idcards && !$graduates && !$honors &&
            !$marrys && !$drives && !$zzjgdmzs && !$yyzzs && !$swdjzs
            && !$rents && !$licencess && !$honorss && !$houses) {
            $this->toJson(-3);
        }
        $legals = array(
            'photos' => $photos ? $photos : '',
            'idcards' => $idcards ? $idcards : '',
            'graduates' => $graduates ? $graduates : '',
            'honors' => $honors ? $honors : '',
            'marrys' => $marrys ? $marrys : '',
            'drives' => $drives ? $drives : '',
        );
        $coms = array(
            'zzjgdmzs' => $zzjgdmzs ? $zzjgdmzs : '',
            'yyzzs' => $yyzzs ? $yyzzs : '',
            'swdjzs' => $swdjzs ? $swdjzs : '',
            'rents' => $rents ? $rents : '',
            'licencess' => $licencess ? $licencess : '',
            'honorss' => $honorss ? $honorss : '',
            'houses' => $houses ? $houses : '',
        );
        $this->service->setComFileLink($uid,$legals,$coms);
        return $this->toJson(0);
    }

    /**
     * ---------------------------------------
     * 公司认证
     * ---------------------------------------
     */





    /**
     * ---------------------------------------
     * 公司的工厂类型
     * ---------------------------------------
     */

    /**
     * 工厂类型列表
     */
    public function getFacTypeList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $cate = $request->cate;
        if (!$token) { return $this->toJson(-2); }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $facTypes = $this->service->getFacTypes();
        return $this->toJson(0,$facTypes);
    }

    /**
     * ---------------------------------------
     * 公司的工厂类型
     * ---------------------------------------
     */





    /**
     * ---------------------------------------
     * 产品产品
     * ---------------------------------------
     */

    /**
     * 产品，获取
     */
    public function getProductList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token || !in_array($cate,[1,2,3])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $zhenList = $this->service->getProductList(19);
        $suoList = $this->service->getProductList(20);
        $baoList = $this->service->getProductList(21);
        $resPros = $this->service->getOptionPro($uid);
        $dataArr = array();
        $zhenIdStr = '';
        $suoIdStr = '';
        $baoIdStr = '';
        foreach ($zhenList as $k=>$v) {
            $dataArr['zhens'][$k]['id'] = $v->id;
            $dataArr['zhens'][$k]['name'] = $v->name;
            if ($resPros && $zhens=$resPros['zhens']) {
                foreach ($zhens as $zhen) {
                    if ($zhen[0]==$v->id) {
                        $dataArr['zhens'][$k]['pros'] = $zhen;
                    }
                }
            } else {
                $dataArr['zhens'][$k]['pros'] = array(0,0,0,0);
            }
            if ($zhenIdStr=='') {
                $zhenIdStr = $v->id;
            } else {
                $zhenIdStr .= '-'.$v->id;
            }
        }
        foreach ($suoList as $k=>$v) {
            $dataArr['suos'][$k]['id'] = $v->id;
            $dataArr['suos'][$k]['name'] = $v->name;
            if ($resPros && $suos=$resPros['suos']) {
                foreach ($suos as $suo) {
                    if ($suo[0]==$v->id) {
                        $dataArr['suos'][$k]['pros'] = $suo;
                    }
                }
            } else {
                $dataArr['suos'][$k]['pros'] = array(0,0,0,0);
            }
            if ($suoIdStr=='') {
                $suoIdStr = $v->id;
            } else {
                $suoIdStr .= '-'.$v->id;
            }
        }
        foreach ($baoList as $k=>$v) {
            $dataArr['baos'][$k]['id'] = $v->id;
            $dataArr['baos'][$k]['name'] = $v->name;
            if ($resPros && $baos=$resPros['baos']) {
                foreach ($baos as $bao) {
                    if ($bao[0]==$v->id) {
                        $dataArr['baos'][$k]['pros'] = $bao;
                    }
                }
            } else {
                $dataArr['baos'][$k]['pros'] = array(0,0,0,0);
            }
            if ($baoIdStr=='') {
                $baoIdStr = $v->id;
            } else {
                $baoIdStr .= '-'.$v->id;
            }
        }
        $dataArr['zhenIdStr'] = $zhenIdStr;
        $dataArr['suoIdStr'] = $suoIdStr;
        $dataArr['baoIdStr'] = $baoIdStr;
        return $this->toJson(0,$dataArr);
    }

    /**
     * 产品，设置
     */
    public function setProduct(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) {
            return $this->toJson(-13);
        }
        $dataArr = array(
            'zhens' => $request->zhens,
            'suos' => $request->suos,
            'baos' => $request->baos,
        );
        $this->service->setOptionPro($uid,$dataArr);
        return $this->toJson(0);
    }

    /**
     * ---------------------------------------
     * 公司产品
     * ---------------------------------------
     */





    /**
     * ---------------------------------------
     * 公司风格
     * ---------------------------------------
     */

    /**
     * 风格，获取
     */
    public function getStyleList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token || !in_array($type,[2,3,4])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $styleList = $this->service->getStyleList();
        if (!$styleList) { return $this->toJson(-3); }
        $resStyles = $this->service->getOptionStyle($uid);
//        return $this->toJson(-1,[$styleList[0]->id,$resStyles[0][0]]);
        $dataArr = array();
        $styleIdStr = '';
        foreach ($styleList as $k=>$v) {
            $dataArr['styles'][$k]['id'] = $v->id;
            $dataArr['styles'][$k]['name'] = $v->name;
            if ($resStyles) {
                foreach ($resStyles as $resStyle) {
                    if ($resStyle[0]==$v->id) {
                        $dataArr['styles'][$k]['check'] = $resStyle[1];
                    }
                }
            } else {
                $dataArr['styles'][$k]['check'] = 0;
            }
            if ($styleIdStr=='') {
                $styleIdStr = $v->id;
            } else {
                $styleIdStr .= '-'.$v->id;
            }
        }
        $dataArr['styleIdStr'] = $styleIdStr;
        return $this->toJson(0,$dataArr);
    }

    /**
     * 风格，设置
     */
    public function setStyle(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token || !in_array($type,[2,3,4])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $styles = $request->styles;
        $this->service->setOptionStyle($uid,$styles);
        return $this->toJson(0);
    }

    /**
     * ---------------------------------------
     * 公司风格
     * ---------------------------------------
     */





    /**
     * ---------------------------------------
     * 公司产品种类
     * ---------------------------------------
     */

    /**
     * 种类，获取
     */
    public function getComProTypeList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token || !in_array($cate,[1,2,3])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $resProTypes = $this->service->getOptionProType($uid);
        if (!$resProTypes) { return $this->toJson(-3); }
        return $this->toJson(0,$resProTypes);
    }

    /**
     * 种类，设置
     */
    public function setComProType(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        if (!$token) { return $this->toJson(-2); }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $proType = $request->proType;
        $this->service->setOptionProType($uid,$proType);
        return $this->toJson(0);
    }

    /**
     * 种类，设置2修改
     */
    public function setComProType2(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $index = $request->index;
        $cates = $request->cates;
        $names = $request->names;
        $males = $request->males;
        $females = $request->females;
        $childs = $request->childs;
        if (!$token || !$index || !$cates || !$names ||
            !$males || !$females || !$childs) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $dataArr = array();
        for ($i=0;$i<$index;$i++) {
            $proTypes = array(
                'cate' => $cates[$i],
                'name' => $names[$i],
                'male' => $males[$i],
                'female' => $females[$i],
                'child' => $childs[$i],
            );
            $dataArr[$i] = $proTypes;
        }
        $this->service->setOptionProType2($uid,$dataArr);
        return $this->toJson(0);
    }

    /**
     * ---------------------------------------
     * 公司产品种类
     * ---------------------------------------
     */





    /**
     * ---------------------------------------
     * 公司款式
     * ---------------------------------------
     */

    /**
     * 款式，获取
     */
    public function getComDesignList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token || !in_array($cate,[1,2,3])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $resStyles = $this->service->getOptionDesign($uid);
        if (!$resStyles) { return $this->toJson(-3); }
        return $this->toJson(0,$resStyles);
    }

    /**
     * 款式，设置
     */
    public function setComDesign(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token || !in_array($cate,[1,2,3])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $design = $request->design;
        $this->service->setOptionDesign($uid,$design);
        return $this->toJson(0);
    }

    /**
     * ---------------------------------------
     * 公司款式
     * ---------------------------------------
     */





    /**
     * ---------------------------------------
     * 公司的工厂设备
     * ---------------------------------------
     */

    /**
     * 工厂设备，获取
     */
    public function getComEquipList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        $equipList = $this->service->getEquipList();
        if (!$equipList) { return $this->toJson(-3); }
        $resEquips = $this->service->getOptionEquip($uid);
        $dataArr = array();
        $equipIdStr = '';
        foreach ($equipList as $k=>$v) {
            $dataArr['equips'][$k]['id'] = $v->id;
            $dataArr['equips'][$k]['name'] = $v->name;
            if ($resEquips) {
                foreach ($resEquips as $k2=>$resEquip) {
                    if ($resEquip[0]==$v->id) {
                        $dataArr['equips'][$k][$k2][1] = $resEquip[1];
                        $dataArr['equips'][$k][$k2][2] = $resEquip[2];
                        $dataArr['equips'][$k][$k2][3] = $resEquip[3];
                        $dataArr['equips'][$k][$k2][4] = $resEquip[4];
                    }
                }
            }
            if ($equipIdStr=='') {
                $equipIdStr = $v->id;
            } else {
                $equipIdStr .= '-'.$v->id;
            }
        }
        $dataArr['equipIdStr'] = $equipIdStr;
        return $this->toJson(0,$dataArr);
    }

    /**
     * 工厂设备，设置
     */
    public function setComEquip(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) {
            return $this->toJson(-13);
        }
        $equips = $request->equips;
        if (!$equips) {
            return $this->toJson(-3);
        }
        $this->service->setOptionEquip($uid,$equips);
        return $this->toJson(0);
    }

    /**
     * ---------------------------------------
     * 公司的工厂设备
     * ---------------------------------------
     */





    /**
     * ---------------------------------------
     * 公司产量产能
     * ---------------------------------------
     */

    /**
     * 产量产能，获取
     */
    public function getComYieldList(Request $request)
    {
        if ($request->app_access != $this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        $yields = $this->service->getOptionYield($uid);
        if (!$yields) { return $this->toJson(-3); }
        return $this->toJson(0,$yields);
    }

    /**
     * 产量产能，设置
     */
    public function setComYield(Request $request)
    {
        if ($request->app_access != $this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) {
            return $this->toJson(-13);
        }
        $yields = $request->yields;
        if (!$yields) {
            return $this->toJson(-3);
        }
        $this->service->setOptionYield($uid,$yields);
        return $this->toJson(0);
    }

    /**
     * ---------------------------------------
     * 公司产量产能
     * ---------------------------------------
     */





    /**
     * ---------------------------------------
     * 公司环境
     * ---------------------------------------
     */

    /**
     * 环境，获取
     */
    public function getComEnvFile(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) { return $this->toJson(-2); }
        $uid = $this->accessGet($token);
        $model = $this->service->getComEnv($uid);
        if (!$model) { return $this->toJson(-3); }
        $dataArr = array(
            'managers' => $model['managers'],
            'manager2s' => $model['manager2s'],
            'directors' => $model['directors'],
            'handles' => $model['handles'],
            'finances' => $model['finances'],
            'officers' => $model['officers'],
            'sales' => $model['sales'],
            'expands' => $model['expands'],
            'designs' => $model['designs'],
            'buyers' => $model['buyers'],
            'sellers' => $model['sellers'],
            'produces' => $model['produces'],
            'qcs' => $model['qcs'],
            'storages' => $model['storages'],
            'transports' => $model['transports'],
            'outs' => $model['outs'],
            'meetings' => $model['meetings'],
            'halls' => $model['halls'],
            'stages' => $model['stages'],
            'talks' => $model['talks'],
            'cooks' => $model['cooks'],
            'wcs' => $model['wcs'],
            'teas' => $model['teas'],
            'dorms' => $model['dorms'],
        );
        return $this->toJson(0,$dataArr);
    }

    /**
     * 环境，图片上传
     */
    public function setComEnvUpload(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return redirect('/h5/error.html?errMsg=接口权限错误');
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        $viewJump = $request->viewJump;
        if (!$token) {
            return redirect('/h5/error.html?errMsg=用户未登录或未注册');
        }
        $uid = $this->accessGet($token);
        if (!isset($request->managerFile) && !isset($request->manager2File) &&
            !isset($request->directorFile) && !isset($request->handleFile) &&
            !isset($request->financeFile) && !isset($request->officerFile) &&
            !isset($request->saleFile) && !isset($request->expandFile) &&
            !isset($request->designFile) && !isset($request->buyerFile) &&
            !isset($request->sellerFile) && !isset($request->produceFile) &&
            !isset($request->qcFile) && !isset($request->storageFile) &&
            !isset($request->transportFile) && !isset($request->outFile) &&
            !isset($request->meetingFile) && !isset($request->hallFile) &&
            !isset($request->stageFile) && !isset($request->talkFile) &&
            !isset($request->cookFile) && !isset($request->wcFile) &&
            !isset($request->teaFile) && !isset($request->dormFile)) {
            return redirect('/h5/error.html?errMsg=文件未上传');
        }
        if (isset($request->managerFile)) {
            $resFile = Upload::uploadImgByApi($request,'managerFile');
            $fileName = 'managers';
        }
        else if (isset($request->manager2File)) {
            $resFile = Upload::uploadImgByApi($request,'manager2File');
            $fileName = 'manager2s';
        }
        else if (isset($request->financeFile)) {
            $resFile = Upload::uploadImgByApi($request,'directorFile');
            $fileName = 'finances';
        }
        else if (isset($request->handleFile)) {
            $resFile = Upload::uploadImgByApi($request,'handleFile');
            $fileName = 'handles';
        }
        else if (isset($request->financeFile)) {
            $resFile = Upload::uploadImgByApi($request,'financeFile');
            $fileName = 'finances';
        }
        else if (isset($request->officerFile)) {
            $resFile = Upload::uploadImgByApi($request,'officerFile');
            $fileName = 'officers';
        }
        else if (isset($request->saleFile)) {
            $resFile = Upload::uploadImgByApi($request,'saleFile');
            $fileName = 'sales';
        }
        else if (isset($request->expandFile)) {
            $resFile = Upload::uploadImgByApi($request,'expandFile');
            $fileName = 'expands';
        }
        else if (isset($request->designFile)) {
            $resFile = Upload::uploadImgByApi($request,'designFile');
            $fileName = 'designs';
        }
        else if (isset($request->buyerFile)) {
            $resFile = Upload::uploadImgByApi($request,'buyerFile');
            $fileName = 'buyers';
        }
        else if (isset($request->sellerFile)) {
            $resFile = Upload::uploadImgByApi($request,'sellerFile');
            $fileName = 'sellers';
        }
        else if (isset($request->produceFile)) {
            $resFile = Upload::uploadImgByApi($request,'produceFile');
            $fileName = 'produces';
        }
        else if (isset($request->qcFile)) {
            $resFile = Upload::uploadImgByApi($request,'qcFile');
            $fileName = 'qcs';
        }
        else if (isset($request->storageFile)) {
            $resFile = Upload::uploadImgByApi($request,'storageFile');
            $fileName = 'storages';
        }
        else if (isset($request->transportFile)) {
            $resFile = Upload::uploadImgByApi($request,'transportFile');
            $fileName = 'transports';
        }
        else if (isset($request->outFile)) {
            $resFile = Upload::uploadImgByApi($request,'outFile');
            $fileName = 'outs';
        }
        else if (isset($request->meetingFile)) {
            $resFile = Upload::uploadImgByApi($request,'meetingFile');
            $fileName = 'meetings';
        }
        else if (isset($request->hallFile)) {
            $resFile = Upload::uploadImgByApi($request,'hallFile');
            $fileName = 'halls';
        }
        else if (isset($request->stageFile)) {
            $resFile = Upload::uploadImgByApi($request,'stageFile');
            $fileName = 'stages';
        }
        else if (isset($request->talkFile)) {
            $resFile = Upload::uploadImgByApi($request,'talkFile');
            $fileName = 'talks';
        }
        else if (isset($request->cookFile)) {
            $resFile = Upload::uploadImgByApi($request,'cookFile');
            $fileName = 'cooks';
        }
        else if (isset($request->wcFile)) {
            $resFile = Upload::uploadImgByApi($request,'wcFile');
            $fileName = 'wcs';
        }
        else if (isset($request->teaFile)) {
            $resFile = Upload::uploadImgByApi($request,'teaFile');
            $fileName = 'teas';
        }
        else if (isset($request->dormFile)) {
            $resFile = Upload::uploadImgByApi($request,'dormFile');
            $fileName = 'dorms';
        }
        else {
            return redirect('/h5/error.html?errMsg=未知错误');
        }
        if ($resFile['code']!=0) {
            return redirect('/h5/error.html?errMsg=图片错误');
        }
        $this->service->setComEnv($uid,$fileName,$resFile['filePath']);
        return redirect($viewJump);
    }

    /**
     * 公司环境，链接设置
     */
    public function setComEnvLink(Request $request)
    {
        if ($request->app_access != $this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        $managers = $request->managers;
        $manager2s = $request->manager2s;
        $directors = $request->directors;
        $handles = $request->handles;
        $finances = $request->finances;
        $officers = $request->officers;
        $sales = $request->sales;
        $expands = $request->expands;
        $designs = $request->designs;
        $buyers = $request->buyers;
        $sellers = $request->sellers;
        $produces = $request->produces;
        $qcs = $request->qcs;
        $storages = $request->storages;
        $transports = $request->transports;
        $outs = $request->outs;
        $meetings = $request->meetings;
        $halls = $request->halls;
        $stages = $request->stages;
        $talks = $request->talks;
        $cooks = $request->cooks;
        $wcs = $request->wcs;
        $teas = $request->teas;
        $dorms = $request->dorms;
        if (!$managers && !$manager2s && !$directors && !$handles &&
            !$finances && !$officers && !$sales && !$expands && !$designs
            && !$buyers && !$sellers && !$produces && !$qcs
            && !$storages && !$transports && !$outs && !$meetings
            && !$halls && !$stages && !$talks && !$cooks
            && !$wcs && !$teas && !$dorms) {
            $this->toJson(-3);
        }
        $dataArr = array(
            'managers' => $managers ? $managers : '',
            'manager2s' => $manager2s ? $manager2s : '',
            'directors' => $directors ? $directors : '',
            'handles' => $handles ? $handles : '',
            'finances' => $finances ? $finances : '',
            'officers' => $officers ? $officers : '',
            'sales' => $sales ? $sales : '',
            'expands' => $expands ? $expands : '',
            'designs' => $designs ? $designs : '',
            'buyers' => $buyers ? $buyers : '',
            'sellers' => $sellers ? $sellers : '',
            'produces' => $produces ? $produces : '',
            'meetings' => $meetings ? $meetings : '',
            'halls' => $halls ? $halls : '',
            'stages' => $stages ? $stages : '',
            'talks' => $talks ? $talks : '',
            'cooks' => $cooks ? $cooks : '',
            'wcs' => $wcs ? $wcs : '',
            'teas' => $teas ? $teas : '',
            'dorms' => $dorms ? $dorms : '',
        );
        $this->service->setComEnvLink($uid, $dataArr);
        return $this->toJson(0, $dataArr);
    }

    /**
     * ---------------------------------------
     * 公司环境
     * ---------------------------------------
     */





    /**
     * ---------------------------------------
     * 公司原料面料
     * ---------------------------------------
     */

    /**
     * 获取
     */
    public function getComFabricList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) { return $this->toJson(-2); }
        $uid = $this->accessGet($token);
        $models = $this->service->getCost($uid);
        if (!$models) { return $this->toJson(-3); }
        $dataArr = $models;
        return $this->toJson(0,$dataArr);
    }

    /**
     * 设置
     */
    public function setComFabric(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) { return $this->toJson(-2); }
        $uid = $this->accessGet($token);
        $costs = $request->costs;
        if (!$costs) { return $this->toJson(-3); }
        $this->service->setCost($uid,$costs);
        return $this->toJson(0);
    }

    /**
     * ---------------------------------------
     * 公司原料面料
     * ---------------------------------------
     */

    /**
     * 资料的完善度
     */
    public function getUserInfoPer(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token) { return $this->toJson(-2); }
        $uid = $this->accessGet($token);
        if (!$uid) {
            return $this->toJson(-13);
        }
        $com = $this->service->getOneByUid($uid);
        $comFile = $this->service->getOptionLicence($uid);
        $comPro = $this->service->getOptionPro($uid);
        $comStyle = $this->service->getOptionStyle($uid);
        $comProType = $this->service->getOptionProType($uid);
        $comDesign = $this->service->getOptionDesign($uid);
        $comEquip = $this->service->getOptionEquip($uid);
        $comYield = $this->service->getOptionYield($uid);
        $comFabric = $this->service->getCost($uid);
        $comEnv = $this->service->getComEnv($uid);
        $dataArr = array( //百分比
            'company' => 0,
            'comFile' => 0,
            'comFacType' => 0,
            'comPro' => 0,
            'comStyle' => 0,
            'comProType' => 0,
            'comDesign' => 0,
            'comEquip' => 0,
            'comYield' => 0,
            'comFabric' => 0,
            'comEnv' => 0
        );
        //基本信息
        if ($com) { $dataArr['company'] = 100; }
        //认证
        if ($comFile) { $dataArr['comFile'] = 100; }
        //工厂类型
        if ($com && $com->facType) { $dataArr['comFacType'] = 100; }
        //产品
        if ($comPro) { $dataArr['comPro'] = 100; }
        //产品风格
        if ($comStyle) { $dataArr['comStyle'] = 100; }
        //产品种类
        if ($comProType) { $dataArr['comProType'] = 100; }
        //产品款式
        if ($comDesign) { $dataArr['comDesign'] = 100; }
        //工厂设备
        if ($comEquip) { $dataArr['comEquip'] = 100; }
        //产量产能
        if ($comYield) { $dataArr['comYield'] = 100; }
        //面料辅料
        if ($comFabric) { $dataArr['comFabric'] = 100; }
        //公司环境
        if ($comEnv) { $dataArr['comEnv'] = 100; }
        return $this->toJson(0,$dataArr);
    }
}